package org.lt.resume.controller.resume;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.struts2.ServletActionContext;
import org.lt.resume.domain.resume.Resume;
import org.lt.resume.service.resumeserviceInterface.ResumeServiceInterface;
import org.lt.resume.util.common.tools.FileOperation;

import com.opensymphony.xwork2.ActionSupport;

public class AddResumeController extends ActionSupport {

	/****/
	private static final long serialVersionUID = -5045014054027962733L;

	private File upload;// The actual file
	private String uploadContentType; // The content type of the file
	private String uploadFileName; // The uploaded file name

//	private String username;

//	private String contactWay;
//
//	private String major;
//
//	private String degree;
//
	private Date graduateDate;
//
//	private String graduateSchool;
//
//	private String citylivein;
//
//	private String oldPosition;
//
//	private String oldCompany;
//
//	private String fitposition;
//
//	private String workExperience;
//
//	private String comment;

	private Resume resumeVO = new Resume();
	
	private ResumeServiceInterface resumeService;

	@Override
	public String execute() throws Exception {
//		System.out.println(username);

		// 获取文件存放到 /upload 目录后的绝对路径，getShortFileName 则只返回文件名，例如：
		// c:\a.txt 则返回 a.txt
		resumeService.addResume(resumeVO);
		String outputFile = ServletActionContext.getServletContext()
				.getRealPath("/upload")
				+ "/" + FileOperation.getShortFileName(resumeVO.getUsername()+uploadFileName);
		System.out.println(uploadFileName);
		if (upload != null) {
			FileOperation.copyFile(upload.getAbsolutePath(), outputFile);
		}
		return SUCCESS;
	}

	public void setUsername(String username) {
		resumeVO.setUsername(username.trim());
	}

	public void setComment(String comment) {
		resumeVO.setComment(comment);
	}

	public void setContactWay(String contactWay) {
		resumeVO.setContactWay(contactWay);
	}

	public void setMajor(String major) {
		resumeVO.setMajor(major);
	}

	public void setDegree(String degree) {
		resumeVO.setDegree(degree);
	}

	public void setGraduateDate(String graduateDate) {
		SimpleDateFormat format2 = new SimpleDateFormat("dd/MM/yyyy");
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			System.out.println(graduateDate);
			this.graduateDate = format.parse(graduateDate);

			//format.format(format2.parse(graduateDate));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		resumeVO.setGraduateDate(this.graduateDate);
	}

	public void setGraduateSchool(String graduateSchool) {
		resumeVO.setGraduateSchool(graduateSchool);
	}

	public void setCitylivein(String citylivein) {
		resumeVO.setCitylivein(citylivein);
	}

	public void setOldPosition(String oldPosition) {
		resumeVO.setOldPosition(oldPosition);
	}

	public void setOldCompany(String oldCompany) {
		resumeVO.setOldCompany(oldCompany);
	}

	public void setFitposition(String fitposition) {
		resumeVO.setFitposition(fitposition);
	}

	public void setWorkExperience(String workExperience) {
		resumeVO.setWorkExperience(workExperience);
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getUploadContentType() {
		return uploadContentType;
	}

	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public Resume getResumeVO() {
		return resumeVO;
	}

	public void setResumeVO(Resume resumeVO) {
		this.resumeVO = resumeVO;
	}

	public ResumeServiceInterface getResumeService() {
		return resumeService;
	}

	public void setResumeService(ResumeServiceInterface resumeService) {
		this.resumeService = resumeService;
	}

}
